package com.luotao.test.netty.jsonnio;

/**
 * Created by IntelliJ IDEA.
 * User: luotao
 * Date: 12-5-30
 * Time: 00:47
 */

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.*;

/**
 * 消息处理类
 */
public class ClientMessageHandler extends SimpleChannelHandler {

	@Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
			throws Exception {
   //     Thread.sleep(2000);
        ChannelBuffer cb = (ChannelBuffer) e.getMessage();
        String content = new String(cb.array());
        System.out.println("content = " + content);
		System.err.println("e.getMessage():"+e.getMessage());
    //    ctx.getChannel().close();
	}
        @Override
    public void handleUpstream(
            ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
        if (e instanceof ChannelStateEvent) {
            System.out.println(e);
        }
        super.handleUpstream(ctx, e);
    }
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
			throws Exception {

		e.getCause().printStackTrace();
        Channel ch = e.getChannel();
//        ch.close();
	}

}
